package org.example.sudoku;

import android.app.IntentService;
import android.content.Intent;
import android.os.Handler;
import android.os.SystemClock;
import android.util.Log;
import android.widget.Toast;

public class TimerSudoku extends IntentService {

	public TimerSudoku() {
		super("TimerSudoku");
	}

	long mStartTime = 0;

	private Handler mTimerHandler = new Handler();

	// Intent notify =new Intent(this,NotificationSudoku.class);

	private Runnable mTimer = new Runnable() {

		public void run() {// od startovanog trenutka do pokretanja , dobija se
							// proteklo vreme
			// proteklo vreme treba oduzeti od nekog zadatog , a onda i
			// izbacivati obavesetnja
			// while (true) {
			// osluskuje se zvanicni casovnik; osluskivati Action_time_tick
			// (svaki minut se desava)
			//

			//na time tic action oduzimati i proveravati preostalo vreme
			long start = mStartTime;
			long millis = SystemClock.uptimeMillis() - start;
			int sec = (int) (millis / 1000);
			int mil = (int) (millis % 1000);
			int min = sec / 60;
			sec %= 60;
			int h = min / 60;
			min = min % 60;
			if (sec < 10) {
				Toast.makeText(getApplicationContext(),
						"wtf minuti su :  " + min + " :0" + sec + " : " + mil,
						Toast.LENGTH_SHORT).show();
				Log.i("vreme", "wtf minuti su :  " + h + " : " + min + " :0"
						+ sec + " : " + mil);
				// NotificationSudoku.setContentText("" + min + ":0" + sec);
			} else {
				// NotificationSudoku.setContentText("" + min + ":" + sec);
			}
			// startService(notify);
			// }
		}
	};

	public void stopirajTimer() {
		mTimerHandler.removeCallbacks(mTimer);

	}

	@Override
	protected void onHandleIntent(Intent intent) {
		if (mStartTime == 0L) {
			mStartTime = SystemClock.uptimeMillis();
			mTimerHandler.removeCallbacks(mTimer);
			mTimerHandler.postDelayed(mTimer, 100);
		}
	}

}
